package com.gitee.feizns.bean;

import com.gitee.feizns.StreamUtils;

import java.util.function.Function;

/**
 * @author feizns
 * @since 2019/6/9 0009
 */
public interface Convertible extends PropertiesIterable {

    /**
     * 复制属性，并新建一个
     * @param targetType
     * @return
     */
    default <T> T to(Class<T> targetType) {
        return to(targetType, StreamUtils::noChangeFun);
    }

    /**
     * 复制属性，并新建一个
     * @param targetType
     * @return
     */
    default <T> T to(Class<T> targetType, Function<String, String> popsMap) {
        return BeanUtils.copyProperties(targetType, popsMap, this);
    }

    /**
     * ...
     * @param target
     * @param <T>
     * @return
     */
    default <T> T to(T target) {
        return to(target, StreamUtils::noChangeFun);
    }

    /**
     * 复制属性，并新建一个
     * @param target
     * @return
     */
    default <T> T to(T target, Function<String, String> popsMap) {
        return BeanUtils.copyProperties(target, popsMap, this);
    }

}
